﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IBLL;
using MisDLL;
using System.Data;

namespace MisBLL
{
    public class CardDAO : MarshalByRefObject, ICard
    {
        protected DbHelper dbHelper = new DbHelper();

        //根据编码查询支付工具信息
        public MisModel.Card GetById(string id)
        {   
            if (string.IsNullOrEmpty(id))
                return null;
            string sql = string.Format("select * from CARD_TAB where CARD_id='{0}'", id);
            DataTable dt=  dbHelper.ExecuteDataTable(sql);
            MisModel.Card entity = null;
            if (dt != null && dt.Rows.Count > 0){
                entity = new MisModel.Card();
                entity.CardID = dt.Rows[0]["CARD_id"].ToString();
                entity.CardName = dt.Rows[0]["CARD"].ToString();
                entity.F1 = dt.Rows[0]["F1"].ToString();
            }
            return entity;
        }

        //查询支付工具列表
        public DataTable GetAll()
        {
            string sql = "select CARD_id,CARD,F1,(CARD_id + '.' + CARD) as ItemShow  from CARD_TAB";
            return dbHelper.ExecuteDataTable(sql);
        }

        //添加支付工具信息
        public int Add(MisModel.Card obj)
        {
            if (string.IsNullOrEmpty(obj.F1.ToString()))
            {
                obj.F1 = "Y";
            }
            string sql = string.Format("insert into CARD_TAB(CARD_id,CARD,F1) values('{0}','{1}','{2}')", obj.CardID, obj.CardName, obj.F1);
            return dbHelper.ExecuteNonQuery(sql);
        }

        //修改支付工具信息
        public int Update(MisModel.Card obj)
        {
            string sql = string.Format("update CARD_TAB set CARD='{0}',F1='{1}' where CARD_id='{2}'", obj.CardName, obj.F1, obj.CardID);
            return dbHelper.ExecuteNonQuery(sql);
        }

        //根据ID删除支付工具信息
        public int Delete(string id)
        {
            string sql = string.Format("delete from CARD_TAB where CARD_id='{0}'", id);
            return dbHelper.ExecuteNonQuery(sql);
        }
    }
}
